package redis_ser

import (
	"gvb_server/global"
	"time"
)

const prefix = "login_"

// Logout 针对注销的操作
func Logout(id, token string) error {
	key := prefix + id
	redis := global.Redis
	err := redis.Exists(key).Err()
	if err != nil {
		return nil
	}
	err = global.Redis.Del(key).Err()
	return err
}

// Login 针对登录的操作
func Login(id string, token string, diff time.Duration) error {
	err := global.Redis.Set(prefix+id, token, diff).Err()
	return err
}

func CheckLogin(id, token string) bool {
	_token := global.Redis.Get(prefix + id)
	if _token == nil || _token.Val() != token {
		return false
	}
	return true
}
